class Watcher {
  constructor(vm, key, cb) {
    this.vm = vm
    this.key = key
    this.cb = cb
    //把watcher对象记录到Dep类的静态属性target
    Dep.target = this
    //触发get方法，在get方法中调用addsub
    this.oldValue = this.vm[key]
    Dep.target = null //防止重复添加
  }
  update() {
    let newValue = this.vm[this.key]
    if(this.oldValue === newValue) return
    this.cb(newValue)
  }
}